﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace Soket_MMTNC_Client
{
    class Ipserver
    {
        public static IPAddress GetIP()
        {
            string localip = "?";
            IPHostEntry host;
            host = Dns.GetHostEntry(Dns.GetHostName());
            foreach (var IP in host.AddressList)
            {
                if (IP.AddressFamily.ToString() == "InterNetwork")
                    localip = IP.ToString();
            }
            return IPAddress.Parse(localip);
        }
        public object HamGiaiMa(byte[] buff)
        {
            MemoryStream ms = new MemoryStream(buff);
            BinaryFormatter bf = new BinaryFormatter();
            ms.Position = 0;
            return bf.Deserialize(ms);
        }

        public byte[] MaHoa(Object o)
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(ms, o);
            return ms.ToArray();
        }
    }
}
